<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="产品编号" prop="productNo">
      <el-input v-model="dataForm.productNo" placeholder="产品编号"></el-input>
    </el-form-item>
    <el-form-item label="模具编号" prop="modelId">
      <el-input v-model="dataForm.modelId" placeholder="模具编号"></el-input>
    </el-form-item>
    <el-form-item label="客户产品编号" prop="clientProductNo">
      <el-input v-model="dataForm.clientProductNo" placeholder="客户产品编号"></el-input>
    </el-form-item>
    <el-form-item label="纸箱编号" prop="boxId">
      <el-input v-model="dataForm.boxId" placeholder="纸箱编号"></el-input>
    </el-form-item>
    <el-form-item label="产品克数" prop="productWeight">
      <el-input v-model="dataForm.productWeight" placeholder="产品克数"></el-input>
    </el-form-item>
    <el-form-item label="产品容量" prop="productVolume">
      <el-input v-model="dataForm.productVolume" placeholder="产品容量"></el-input>
    </el-form-item>
    <el-form-item label="容量备注" prop="volumeRemark">
      <el-input v-model="dataForm.volumeRemark" placeholder="容量备注"></el-input>
    </el-form-item>
    <el-form-item label="产品图片" prop="productImageId">
      <el-input v-model="dataForm.productImageId" placeholder="产品图片"></el-input>
    </el-form-item>
    <el-form-item label="产品图纸" prop="productDrawingId">
      <el-input v-model="dataForm.productDrawingId" placeholder="产品图纸"></el-input>
    </el-form-item>
    <el-form-item label="瓶口内径" prop="bottleInDiameter">
      <el-input v-model="dataForm.bottleInDiameter" placeholder="瓶口内径"></el-input>
    </el-form-item>
    <el-form-item label="瓶口外径" prop="bottleOutDiameter">
      <el-input v-model="dataForm.bottleOutDiameter" placeholder="瓶口外径"></el-input>
    </el-form-item>
    <el-form-item label="口径" prop="productCaliber">
      <el-input v-model="dataForm.productCaliber" placeholder="口径"></el-input>
    </el-form-item>
    <el-form-item label="长宽高" prop="lengthWeightHeight">
      <el-input v-model="dataForm.lengthWeightHeight" placeholder="长宽高"></el-input>
    </el-form-item>
    <el-form-item label="产品问题" prop="productQuestion">
      <el-input v-model="dataForm.productQuestion" placeholder="产品问题"></el-input>
    </el-form-item>
    <el-form-item label="产品组合套" prop="productAssort">
      <el-input v-model="dataForm.productAssort" placeholder="产品组合套"></el-input>
    </el-form-item>
    <el-form-item label="产品后续加工" prop="productTrailingProcess">
      <el-input v-model="dataForm.productTrailingProcess" placeholder="产品后续加工"></el-input>
    </el-form-item>
    <el-form-item label="产品备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="产品备注"></el-input>
    </el-form-item>
    <el-form-item label="产品成品率" prop="successRate">
      <el-input v-model="dataForm.successRate" placeholder="产品成品率"></el-input>
    </el-form-item>
    <el-form-item label="产品分类" prop="productCategoryId">
      <el-input v-model="dataForm.productCategoryId" placeholder="产品分类"></el-input>
    </el-form-item>
    <el-form-item label="创建日期" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建日期"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createUser">
      <el-input v-model="dataForm.createUser" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="更新人员" prop="updateUser">
      <el-input v-model="dataForm.updateUser" placeholder="更新人员"></el-input>
    </el-form-item>
    <el-form-item label="0为启用，1为禁止" prop="status">
      <el-input v-model="dataForm.status" placeholder="0为启用，1为禁止"></el-input>
    </el-form-item>
    <el-form-item label="客户ID" prop="clientId">
      <el-input v-model="dataForm.clientId" placeholder="客户ID"></el-input>
    </el-form-item>
    <el-form-item label="克重误差" prop="weightScope">
      <el-input v-model="dataForm.weightScope" placeholder="克重误差"></el-input>
    </el-form-item>
    <el-form-item label="容量误差" prop="volumeScope">
      <el-input v-model="dataForm.volumeScope" placeholder="容量误差"></el-input>
    </el-form-item>
    <el-form-item label="瓶高" prop="bottleHeight">
      <el-input v-model="dataForm.bottleHeight" placeholder="瓶高"></el-input>
    </el-form-item>
    <el-form-item label="头颈高度" prop="headNeckHeight">
      <el-input v-model="dataForm.headNeckHeight" placeholder="头颈高度"></el-input>
    </el-form-item>
    <el-form-item label="拟上机设备" prop="deviceId">
      <el-input v-model="dataForm.deviceId" placeholder="拟上机设备"></el-input>
    </el-form-item>
    <el-form-item label="瓶长" prop="bottleLength">
      <el-input v-model="dataForm.bottleLength" placeholder="瓶长"></el-input>
    </el-form-item>
    <el-form-item label="瓶子宽" prop="bottleWeight">
      <el-input v-model="dataForm.bottleWeight" placeholder="瓶子宽"></el-input>
    </el-form-item>
    <el-form-item label="公共属性ID" prop="productCommonId">
      <el-input v-model="dataForm.productCommonId" placeholder="公共属性ID"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          productNo: '',
          modelId: '',
          clientProductNo: '',
          boxId: '',
          productWeight: '',
          productVolume: '',
          volumeRemark: '',
          productImageId: '',
          productDrawingId: '',
          bottleInDiameter: '',
          bottleOutDiameter: '',
          productCaliber: '',
          lengthWeightHeight: '',
          productQuestion: '',
          productAssort: '',
          productTrailingProcess: '',
          remark: '',
          successRate: '',
          productCategoryId: '',
          createTime: '',
          createUser: '',
          updateTime: '',
          updateUser: '',
          status: '',
          clientId: '',
          weightScope: '',
          volumeScope: '',
          bottleHeight: '',
          headNeckHeight: '',
          deviceId: '',
          bottleLength: '',
          bottleWeight: '',
          productCommonId: ''
        },
        dataRule: {
          productNo: [
            { required: true, message: '产品编号不能为空', trigger: 'blur' }
          ],
          modelId: [
            { required: true, message: '模具编号不能为空', trigger: 'blur' }
          ],
          clientProductNo: [
            { required: true, message: '客户产品编号不能为空', trigger: 'blur' }
          ],
          boxId: [
            { required: true, message: '纸箱编号不能为空', trigger: 'blur' }
          ],
          productWeight: [
            { required: true, message: '产品克数不能为空', trigger: 'blur' }
          ],
          productVolume: [
            { required: true, message: '产品容量不能为空', trigger: 'blur' }
          ],
          volumeRemark: [
            { required: true, message: '容量备注不能为空', trigger: 'blur' }
          ],
          productImageId: [
            { required: true, message: '产品图片不能为空', trigger: 'blur' }
          ],
          productDrawingId: [
            { required: true, message: '产品图纸不能为空', trigger: 'blur' }
          ],
          bottleInDiameter: [
            { required: true, message: '瓶口内径不能为空', trigger: 'blur' }
          ],
          bottleOutDiameter: [
            { required: true, message: '瓶口外径不能为空', trigger: 'blur' }
          ],
          productCaliber: [
            { required: true, message: '口径不能为空', trigger: 'blur' }
          ],
          lengthWeightHeight: [
            { required: true, message: '长宽高不能为空', trigger: 'blur' }
          ],
          productQuestion: [
            { required: true, message: '产品问题不能为空', trigger: 'blur' }
          ],
          productAssort: [
            { required: true, message: '产品组合套不能为空', trigger: 'blur' }
          ],
          productTrailingProcess: [
            { required: true, message: '产品后续加工不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '产品备注不能为空', trigger: 'blur' }
          ],
          successRate: [
            { required: true, message: '产品成品率不能为空', trigger: 'blur' }
          ],
          productCategoryId: [
            { required: true, message: '产品分类不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建日期不能为空', trigger: 'blur' }
          ],
          createUser: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          updateUser: [
            { required: true, message: '更新人员不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '0为启用，1为禁止不能为空', trigger: 'blur' }
          ],
          clientId: [
            { required: true, message: '客户ID不能为空', trigger: 'blur' }
          ],
          weightScope: [
            { required: true, message: '克重误差不能为空', trigger: 'blur' }
          ],
          volumeScope: [
            { required: true, message: '容量误差不能为空', trigger: 'blur' }
          ],
          bottleHeight: [
            { required: true, message: '瓶高不能为空', trigger: 'blur' }
          ],
          headNeckHeight: [
            { required: true, message: '头颈高度不能为空', trigger: 'blur' }
          ],
          deviceId: [
            { required: true, message: '拟上机设备不能为空', trigger: 'blur' }
          ],
          bottleLength: [
            { required: true, message: '瓶长不能为空', trigger: 'blur' }
          ],
          bottleWeight: [
            { required: true, message: '瓶子宽不能为空', trigger: 'blur' }
          ],
          productCommonId: [
            { required: true, message: '公共属性ID不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/relate/relatelightbottleproduct/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.productNo = data.relateLightBottleProduct.productNo
                this.dataForm.modelId = data.relateLightBottleProduct.modelId
                this.dataForm.clientProductNo = data.relateLightBottleProduct.clientProductNo
                this.dataForm.boxId = data.relateLightBottleProduct.boxId
                this.dataForm.productWeight = data.relateLightBottleProduct.productWeight
                this.dataForm.productVolume = data.relateLightBottleProduct.productVolume
                this.dataForm.volumeRemark = data.relateLightBottleProduct.volumeRemark
                this.dataForm.productImageId = data.relateLightBottleProduct.productImageId
                this.dataForm.productDrawingId = data.relateLightBottleProduct.productDrawingId
                this.dataForm.bottleInDiameter = data.relateLightBottleProduct.bottleInDiameter
                this.dataForm.bottleOutDiameter = data.relateLightBottleProduct.bottleOutDiameter
                this.dataForm.productCaliber = data.relateLightBottleProduct.productCaliber
                this.dataForm.lengthWeightHeight = data.relateLightBottleProduct.lengthWeightHeight
                this.dataForm.productQuestion = data.relateLightBottleProduct.productQuestion
                this.dataForm.productAssort = data.relateLightBottleProduct.productAssort
                this.dataForm.productTrailingProcess = data.relateLightBottleProduct.productTrailingProcess
                this.dataForm.remark = data.relateLightBottleProduct.remark
                this.dataForm.successRate = data.relateLightBottleProduct.successRate
                this.dataForm.productCategoryId = data.relateLightBottleProduct.productCategoryId
                this.dataForm.createTime = data.relateLightBottleProduct.createTime
                this.dataForm.createUser = data.relateLightBottleProduct.createUser
                this.dataForm.updateTime = data.relateLightBottleProduct.updateTime
                this.dataForm.updateUser = data.relateLightBottleProduct.updateUser
                this.dataForm.status = data.relateLightBottleProduct.status
                this.dataForm.clientId = data.relateLightBottleProduct.clientId
                this.dataForm.weightScope = data.relateLightBottleProduct.weightScope
                this.dataForm.volumeScope = data.relateLightBottleProduct.volumeScope
                this.dataForm.bottleHeight = data.relateLightBottleProduct.bottleHeight
                this.dataForm.headNeckHeight = data.relateLightBottleProduct.headNeckHeight
                this.dataForm.deviceId = data.relateLightBottleProduct.deviceId
                this.dataForm.bottleLength = data.relateLightBottleProduct.bottleLength
                this.dataForm.bottleWeight = data.relateLightBottleProduct.bottleWeight
                this.dataForm.productCommonId = data.relateLightBottleProduct.productCommonId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/relate/relatelightbottleproduct/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'productNo': this.dataForm.productNo,
                'modelId': this.dataForm.modelId,
                'clientProductNo': this.dataForm.clientProductNo,
                'boxId': this.dataForm.boxId,
                'productWeight': this.dataForm.productWeight,
                'productVolume': this.dataForm.productVolume,
                'volumeRemark': this.dataForm.volumeRemark,
                'productImageId': this.dataForm.productImageId,
                'productDrawingId': this.dataForm.productDrawingId,
                'bottleInDiameter': this.dataForm.bottleInDiameter,
                'bottleOutDiameter': this.dataForm.bottleOutDiameter,
                'productCaliber': this.dataForm.productCaliber,
                'lengthWeightHeight': this.dataForm.lengthWeightHeight,
                'productQuestion': this.dataForm.productQuestion,
                'productAssort': this.dataForm.productAssort,
                'productTrailingProcess': this.dataForm.productTrailingProcess,
                'remark': this.dataForm.remark,
                'successRate': this.dataForm.successRate,
                'productCategoryId': this.dataForm.productCategoryId,
                'createTime': this.dataForm.createTime,
                'createUser': this.dataForm.createUser,
                'updateTime': this.dataForm.updateTime,
                'updateUser': this.dataForm.updateUser,
                'status': this.dataForm.status,
                'clientId': this.dataForm.clientId,
                'weightScope': this.dataForm.weightScope,
                'volumeScope': this.dataForm.volumeScope,
                'bottleHeight': this.dataForm.bottleHeight,
                'headNeckHeight': this.dataForm.headNeckHeight,
                'deviceId': this.dataForm.deviceId,
                'bottleLength': this.dataForm.bottleLength,
                'bottleWeight': this.dataForm.bottleWeight,
                'productCommonId': this.dataForm.productCommonId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
